Attribute VB_Name = "Startup"
'====================================================================================
'StartUp - What this app does to begin with
'====================================================================================
Option Explicit

'Used by 'SharedStartUp' to find previous instances of the app
Public Const AppTitle = "Pac Mar"

'====================================================================================
'StartProgram: First unique steps for this app. Comes from 'SharedStartUp'
'====================================================================================
Public Sub StartProgram()
    'Define the difficulty level settings
    With DiffModes(0)
        .Title = "Learner"
        .TimeLimit = (3.5 * 60)
        .MarSpeed = 5
        .DibSpeed = 2: .ZimSpeed = 2: .KrocSpeed = 2: .GirSpeed = 2
        .LoveTime = 256
        .PickupInterval = 45: .PickupWaitTime = 15: .PickupTimeout = 10
    End With
    With DiffModes(1)
        .Title = "Easy"
        .TimeLimit = (3 * 60)
        .MarSpeed = 5
        .DibSpeed = 3: .ZimSpeed = 3: .KrocSpeed = 2: .GirSpeed = 2
        .LoveTime = 256
        .PickupInterval = 45: .PickupWaitTime = 15: .PickupTimeout = 10
    End With
    With DiffModes(2)
        .Title = "Medium"
        .TimeLimit = (2.5 * 60)
        .MarSpeed = 6
        .DibSpeed = 3: .ZimSpeed = 3: .KrocSpeed = 3: .GirSpeed = 3
        .LoveTime = 192
        .PickupInterval = 45: .PickupWaitTime = 15: .PickupTimeout = 10
    End With
    With DiffModes(3)
        .Title = "Hard"
        .TimeLimit = (2 * 60)
        .MarSpeed = 7
        .DibSpeed = 4: .ZimSpeed = 4: .KrocSpeed = 3: .GirSpeed = 3
        .LoveTime = 128
        .PickupInterval = 45: .PickupWaitTime = 15: .PickupTimeout = 10
    End With
    With DiffModes(4)
        .Title = "Hardcore"
        .TimeLimit = (1.5 * 60)
        .MarSpeed = 7
        .DibSpeed = 4: .ZimSpeed = 4: .KrocSpeed = 4: .GirSpeed = 4
        .LoveTime = 0
        .PickupInterval = 45: .PickupWaitTime = 15: .PickupTimeout = 10
    End With
    With DiffModes(5)   'A difficulty level for testing the game
        .Title = "Debug"
        .TimeLimit = (10 * 60) - 1
        .MarSpeed = 2
        .DibSpeed = 1: .ZimSpeed = 1: .KrocSpeed = 1: .GirSpeed = 1
        .LoveTime = 512
        .PickupInterval = 15: .PickupWaitTime = 15: .PickupTimeout = 10
    End With
    
    'Create the classes that control the game
    Set Game = New clsGame
    
    'Load the display Window
    Load FrmGame
    
    'Load the high scores table
    HighScores.Load "Game"
    
    'Load all the sprites and images
    LoadResources
    'Preload the particle effects
    Set GameMedia.Particles = New clsParticleHandler
    'Create the statusbars top and bottom
    Set Status = New clsStatusBars
    
    'Check if fullscreen mode is requested, or the user is using 640x480 desktop _
     resolution anyway (as the titlebar and startbar will block some of the game)
    If (InStr(1, Command(), "-fullscreen") > 0) Or _
       (Screen.Height \ Screen.TwipsPerPixelY = 480) _
    Then
        'Switch to fullscreen and flag it, if it succeded
        Fullscreen.Switch FrmGame, True
    End If
    
    'Check if the -nologo switch has been specified, to ignore showing the logos
    If (InStr(1, Command(), "-nologo") > 0) Then
        Startup.AfterLogo
    Else
        'Start the game with the Camen Design logo
        Project.StartLogo
    End If
    
    'Begin animation
    FrmGame.StartAllTimers True
End Sub

'====================================================================================
'AfterLogo: Once the Camen Design logo is shown decide where to go
'====================================================================================
Public Sub AfterLogo()
    Dim tStart As Long, tEnd As Long
    Dim tFile As String
    
    'Atfer the Camen Design logo either go to the Title Screen, or depending on _
     command line switches, go straight to game.
    If (InStr(1, Command(), "-map:") > 0) Then
        'Get the level file in the command line
        tStart = InStr(1, Command(), "-map:") + 5
        tEnd = InStr(tStart, Command(), ".pmlvl") + 5
        tFile = Replace(Mid(Command(), tStart, tEnd), Chr(34), "")
        Game.Round = 1
        'Begin gameplay on this level
        Game.StartGame tFile
    Else
        'Show the titlescreen
        Project.StartTitleScreen
    End If
End Sub

'====================================================================================
'ExitGame: Close the doors before ending the program
'====================================================================================
Public Sub ExitGame()
    'overide the status text and then change animation modes to close the doors _
     see Animate() function above for details.
    Status.SetMessageBottom "Goodbye! n_n", SLIDEDOWN, 100, True
    GameMode = GM_Exit
End Sub

'====================================================================================
'EndProgram: A safe way to end the program and ensure everything is unloaded
'====================================================================================
Public Sub EndProgram()
    'Stop the animation
    FrmGame.StartAllTimers False
    
    'Exit fullscreen mode
    If Fullscreen.IsFullscreen = True Then Fullscreen.Switch FrmGame, False
    
    'Absolutely everything must be removed from memory otherwise the EXE will _
     continue to run in the background even though nothing is on screen.
    Set GameMedia.Particles = Nothing
    Set Status = Nothing
    Set Level = Nothing
    Set GameScreen = Nothing    'Detach any current screen
    Set Game = Nothing
    
    'Unload all the shared graphics / sprites etc
    UnloadResources
    
    'This loop to unload all forms (both your own and VB's memory constructs) is _
     absolutely required in order to be able to end the program without using the _
     End command.
    Dim frm As Form
    For Each frm In Forms: Unload frm: Next
    
    'Don't use the End command in VB, memory isn't freed up properly, also the End _
     command often crashes VB when API calls are in use.
    
    'If there's any major objects still in memory, then the window will close, but _
     the IDE will not exit running mode, this way you can tell when you've got _
     something still loaded.
    
    'END OF LINE
End Sub

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
